﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;

namespace ConsoleApplication1
{
    public class TransponderPassing : BackgroundWorker
    {
        public int TransponderId
        {
            get;
            set;
        }

        protected override void OnDoWork(DoWorkEventArgs e)
        {
            base.OnDoWork(e);

            Random rand = new Random((int)DateTime.Now.Ticks);

            Thread.Sleep(1000);

            while (true)
            {
                Random r = new Random((int)DateTime.Now.Ticks);

                int time = r.Next(14, 24);

                TimeSpan t = new TimeSpan(0, 0, 0, time, (int)r.NextDouble() * 1000);

                try
                {
                    Thread.Sleep((int)Math.Ceiling(t.TotalMilliseconds));

                    ReportProgress(0, BitConverter.GetBytes(this.TransponderId));
                }
                catch (Exception)
                {
                }
            }
        }
    }
}
